--  增强输入测试
-- DESCRIPTION
--
-- @COMPANY **
-- @AUTHOR **
-- @DATE ${date} ${time}
--

---@type BP_CharacterTest_C
local M = UnLua.Class()

-- function M:Initialize(Initializer)
-- end

-- function M:UserConstructionScript()
-- end

function M:ReceiveBeginPlay()

    -- 添加控件映射上下文
    local playerController = self:GetController():Cast(UE.APlayerController)
    local EnhancedInput = UE.UEnhancedInputLocalPlayerSubsystem
    EnhancedInput = UE.USubsystemBlueprintLibrary.GetLocalPlayerSubSystemFromPlayerController(playerController, UE.UEnhancedInputLocalPlayerSubsystem)

    if EnhancedInput then
        local ActionPath = "/ActionPlatformer/Input/IMC_Action.IMC_Action"  -- EnhancedInput.InputMappingContext 文件添加 
        local InputAction = UE.UObject.Load(ActionPath)
        -- print("绑定成功" .. " " .. tostring(InputAction))  
        EnhancedInput:AddMappingContext(InputAction, 0, nil)
    end
end

-- 增强输入绑定操作
local BindAction = UnLua.EnhancedInput.BindAction
-- 测试的按键
local IA_Test = "/ActionPlatformer/Input/Actions/IA_Test.IA_Test" -- EnhancedInput.InputAction 资产添加

--[[ 按键的状态
  Triggered              发生在Tick后持续
  Started                发生按下
  Ongoing                长时间按下
  Canceled               取消按下
  Completed              按键完成]]

--[[
 为当前模块绑定操作输入响应
 1.Module table @需要绑定的lua模块
 2.InputAction string @绑定的操作资源路径，是个UInputAction
 3.TriggerEvent string @绑定的事件名称，参考ETriggerEvent下的命名
 4.Handler fun(Key:FKey) @事件响应回调函数
 5.Args table @[opt]扩展参数  两个参数，经过了几秒，第二个是触发的秒数
]]

---UnLua绑定按键，应用UE5的增强输入
BindAction(M, IA_Test, "Triggered", function(self, ActionValue, A, B)
    TestStartedAction(ActionValue, A, B)
end)

-- 测试按键按下行为
function TestStartedAction(ActionValue, A, B)
    print("IA_Test Started")
    print(tostring(ActionValue))
    print(tostring(A))
    print(tostring(B))

end

BindAction(M, IA_Test, "Completed", function(self, ActionValue, A, B)
    TestCompletedAction(ActionValue, A, B)
end)

function TestCompletedAction(ActionValue, A, B)
    print("IA_Test Completed")
    print(tostring(ActionValue))
    print(tostring(A))
    print(tostring(B))
end

-- function M:ReceiveEndPlay()
-- end

-- function M:ReceiveTick(DeltaSeconds)
-- end

-- function M:ReceiveAnyDamage(Damage, DamageType, InstigatedBy, DamageCauser)
-- end

-- function M:ReceiveActorBeginOverlap(OtherActor)
-- end

-- function M:ReceiveActorEndOverlap(OtherActor)
-- end

return M
